﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using DataAccess.Entities;
using Zeenck.DataAccess.Repositories;

namespace Zeenck.Controllers
{
    public class ValidationController : Controller
    {
        public JsonResult IsUsernameAvaliable(string Username)
        {
            IRepository<Account> repository = new AccountRepository();
            List<Account> accounts = repository.GetAll().ToList();

            if (!accounts.Exists(x => x.UserName == Username))
                return Json(true, JsonRequestBehavior.AllowGet);

            string returnString = String.Format("{0} is not available", Username);
            return Json(returnString, JsonRequestBehavior.AllowGet);
        }

    }
}
